package com.system.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.system.entity.OrganizeInfo;
import com.system.service.IOrganizeService;
import com.system.service.OrganizeServiceImpl;

public class AddOrganizeInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public AddOrganizeInfoServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html");
		request.setCharacterEncoding("utf-8");
		
		String infoNum = request.getParameter("id");
		String infoName = request.getParameter("name");
		String infoContent = request.getParameter("content");
		IOrganizeService organizeService = new OrganizeServiceImpl();
		OrganizeInfo organizeInfo = new OrganizeInfo(infoNum, infoName, infoContent);
		PrintWriter out = response.getWriter();
		if (organizeService.addOrganizeInfo(organizeInfo) == "1") {
			out.print("{\"code\":\"1\"}");
		}else {
			out.print("{\"code\":\"0\"}");
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
